package com.android.gl2jni.filter;

import android.content.Context;
import com.android.gl2jni.ShaderUtils;

/**
 * Create time: 2018/9/15.
 */
public class TileMosaicFilterProgram extends TextureFilterProgram {
  private int miResolutionLoc;
  private int tileSizeLoc;
  private int borderSizeLoc;
  private int tileSize = 10;
  private int borderSize = 1;

  /**
   * Prepares the program in the current EGL context.
   */
  public TileMosaicFilterProgram(Context context) {
    super(context, ProgramType.TEXTURE_EXT);
  }

  @Override
  protected void initProgram() {
    super.initProgram();
    tileSizeLoc = getUniformLocation("tileSize");
    borderSizeLoc = getUniformLocation("borderSize");
    miResolutionLoc = getUniformLocation("iResolution");
  }

  @Override
  protected void onDraw(int firstVertex, int vertexCount) {
    setFloatVec3(miResolutionLoc, new float[]{(float) surfaceWidth, (float) surfaceHeight, 1.0f});
    setFloat(tileSizeLoc, tileSize);
    setFloat(borderSizeLoc, borderSize);
    super.onDraw(firstVertex, vertexCount);
  }

  public void setTileSize(int tileSize) {
    this.tileSize = tileSize;
  }

  public void setBorderSize(int borderSize) {
    this.borderSize = borderSize;
  }

  @Override
  protected String getFragmentShaderSourceEXT() {
    return ShaderUtils.readAssetsTextFile(getContext(),
        "filter/fsh/shadertoy/tile_mosaic.glsl");
  }

}
